package com.thread;

public class TheadToStop extends Thread{
	public final static String uuid = Math.random()*10+"";// TODO 获取活着的线程
	 //共享变量  
    private volatile boolean isStop = false;  
      
    @Override  
    public void interrupt(){  
    //调用interrupt之前，把isStop置为false  
    isStop = true;  
    super.interrupt();  
    }  
      
    @Override  
    public void run(){  
    System.out.println(Thread.currentThread().getName() + " is going to run");  
      
    // double check，检查stop的状态   
    while(!isStop){  
        System.out.println(Thread.currentThread().getName() + " is running");  
        try {  
        Thread.sleep(400);  
//        System.out.println(1/0);
        } catch (InterruptedException e) { 
        	e.printStackTrace();
          System.out.println(Thread.currentThread().getName() + " is interrupt");  
        }  
    }  
    System.out.println(Thread.currentThread().getName() + " is exiting");  
    }  
}
